package xyz.yuelai.blog.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;

import xyz.yuelai.blog.dao.IArticleDetailDAO;
import xyz.yuelai.blog.entity.ArticleBrief;
import xyz.yuelai.blog.entity.ArticleDetail;
import xyz.yuelai.blog.service.IArticleDetailService;
import xyz.yuelai.blog.util.PageInfoUtil;

@Service("articleDetailService")
public class ArticleDetailServiceImpl implements IArticleDetailService {

	@Autowired
	private IArticleDetailDAO articleDetailDAO;

	@Override
	public void saveArticleDetail(ArticleDetail articleDetail) {
		articleDetailDAO.saveArticleDetail(articleDetail);
	}

	@Override
	public void deleteArticleDetail(Map<String, Object> conditionMap) {
		articleDetailDAO.deleteArticleDetail(conditionMap);
	}

	@Override
	public void updateArticleDetail(ArticleDetail articleDetail) {
		articleDetailDAO.updateArticleDetail(articleDetail);
	}

	@Override
	public ArticleDetail getArticleDetail(Map<String, Object> conditionMap) {
		return articleDetailDAO.getArticleDetail(conditionMap);
	}

	@Override
	public List<ArticleDetail> getArticleDetailList(PageInfoUtil pageInfoUtil, Map<String, Object> conditionMap) {
		if (pageInfoUtil != null) {
			Page<ArticleBrief> page = PageMethod.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<ArticleDetail> articleDetailList = articleDetailDAO.getArticleDetailList(conditionMap);
			pageInfoUtil.setTotalRecord((int) page.getTotal());
			return articleDetailList;
		}
		return articleDetailDAO.getArticleDetailList(conditionMap);
	}
}
